package red.lixiang.controller;

import red.lixiang.model.BaseInfo;
import red.lixiang.service.ReportService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;

@Controller
public class ReportController {

    private   final Logger logger = Logger.getLogger(MemberController.class.getName());

    @Autowired
    private ReportService reportService;

    @GetMapping("/report/showReportPage")
    public String showReportPage(){
        logger.info("come in report");
        return "report";
    }

    @GetMapping("/report/getSaleData/{date}")
    @ResponseBody
    public String getSaleData(@PathVariable String date){
        System.out.println(date);
        logger.info("come in report");
        BaseInfo baseInfo = reportService.getSaleReport(date);
        HashMap<String ,List> map = new HashMap<>();
        map.put("data", (List) baseInfo.getObject());
        return JSON.toJSONString(map);
    }

    @GetMapping("/report/getSaleDataWithBeginEnd/{beginDate}/{endDate}")
    @ResponseBody
    public String getSaleDataWithBeginEnd(@PathVariable String beginDate, @PathVariable String endDate){
        logger.info("come in getSaleDataWithBeginEnd");
        BaseInfo baseInfo = reportService.getSaleReportWithBeginEnd(beginDate, endDate);
        HashMap<String ,List> map = new HashMap<>();
        map.put("data", (List) baseInfo.getObject());
        return JSON.toJSONString(map);
    }

    @GetMapping("/report/contactMember/{memberId}/{orderId}")
    @ResponseBody
    public String contactMember(@PathVariable Integer memberId , @PathVariable Integer orderId){

        logger.info("come in report/contactMember");
        BaseInfo baseInfo = reportService.contactMember(memberId, orderId);
        return JSON.toJSONString(baseInfo);
    }
}
